﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace Acc.Lib
{
    public static class Json
    {
        static public string Serialize(this object o)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(o);
        }

        static public T Deserialize<T>(this string o)
        {
            try
            {
                return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(o);
            }
            catch
            {
                return default(T);
            }
        }

        static public String UrlEncoding(this String str, Encoding encoding)
        {
            return HttpUtility.UrlEncode(str, encoding);
        }

        public static String UrlDecode(this String str, Encoding encoding)
        {
            return HttpUtility.UrlDecode(str, encoding);
        }

    }
}
